#ifndef MATRIXMODEL_H
#define MATRIXMODEL_H

#include <QAbstractTableModel>

class MatrixBase;
class MatrixModelPrivate;
class MatrixModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    explicit MatrixModel(QObject* parent = nullptr);
    ~MatrixModel();

    void setAutoRelease(bool release);
    bool isAutoRelease() const;

    void setMatrix(const QSharedPointer<MatrixBase>& matrix);
    QSharedPointer<MatrixBase> matrix() const;

    int rowCount(const QModelIndex & parent = QModelIndex()) const;
    int columnCount(const QModelIndex & parent = QModelIndex()) const;

    Qt::ItemFlags flags (const QModelIndex &index) const;
    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);

    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

    void setHorizontalHeaderData(const QVector<double>& data);
    QVector<double> horizontalHeaderData() const;

    void setVerticalHeaderData(const QVector<double>& data);
    QVector<double> verticalHeaderData() const;

private slots:
    void onMatrixValueChanged(int row, int column, const QVariant& oldVal, const QVariant& newVal);

private:
    MatrixModelPrivate* d_ptr;
};

#endif // MATRIXMODEL_H
